import { defineStore } from 'pinia'

export default defineStore('user', {
  state: () => {
    return {
      username: 'admin',
      count: 1
    }
  },
  actions: {
    SET_DATA(value: string) {
      this.username = value
      this.count++
    },
    async getAxiosData(value: Object) {
      console.log(value, 'valueObject');

      // const res = await xxx(value)
      // 模拟res数据
      let res = {
        code: 200,
        data: [
          {
            label: '666',
            value: '555'
          },
          {
            label: '666',
            value: '555'
          }
        ]
      }
      if (res.code == 200) {
        // 将数据存储到state中
        // 1..
        // 2..

        // 将数据return出
        return res
      }
    }
  },
  getters: {
    getCount(state) {
      // console.log(state, 'state');
      return state.count * 2
    }
  },
  // persist: {
  //   enabled: true
  // }
})

